package com.ruoyi.user.utils;

import java.io.InputStream;
import java.security.PublicKey;

/**
 * @author houyong
 */
public class SecurityUtils {

    /**
     * 加密
     *
     * @param plainTest 明文
     * @return 返回加密后的密文
     * @throws Exception
     */
    public static String encrypt(String plainTest) throws Exception {
//        FileInputStream inPublic = new FileInputStream(
//                SecurityUtils.class.getClassLoader().getResource("").getPath() + "/rsa_public_key.pem");


        InputStream inPublic = SecurityUtils.class.getClassLoader().getResourceAsStream("rsa_public_key.pem");

        PublicKey publicKey = RSAUtils.loadPublicKey(inPublic);
        byte[] encryptByte = RSAUtils.encryptData(plainTest.getBytes(), publicKey);
        String afterencrypt = Base64Utils.encode(encryptByte);
        return afterencrypt;
    }


}
